/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package ticketbooking;

import java.io.BufferedInputStream;
import java.security.Key;
import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.Signature;
import java.security.PrivateKey;
import java.security.PublicKey;

/**
 *
 * @author Kse7en
 */
public class DigitalSignature {
        
        public static byte[] sign(byte[] data, PrivateKey privateKey) throws Exception {
                
                Signature dsa = Signature.getInstance("SHA1withRSA");
                dsa.initSign(privateKey);
                dsa.update(data);
                byte[] realSig = dsa.sign();
                
                return realSig;
        }
        
        public static boolean verify(byte[] data, PublicKey publicKey, byte[] Sign) throws Exception {
                
                Signature sig = Signature.getInstance("SHA1withRSA");
                sig.initVerify(publicKey);
                sig.update(data);
                
                boolean verifies = sig.verify(Sign);

                return verifies;
        }
}
